package com.example.demo.service;

import com.example.demo.entity.ArticleInfo;
import com.example.demo.mapper.ArticleMapper;
import com.example.demo.mapper.LikeRcountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description:
 * User: 故我
 * Date: 2023-11-09
 * Time: 14:39
 */
@Service
public class ArticleSevice {
    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    private LikeRcountMapper likeRcountMapper;

    public Integer getArtCountByUid(Integer uid) {
        return articleMapper.getArtCountByUid(uid);
    }

    public List<ArticleInfo> getArtListByUid(Integer uid) {
        return articleMapper.getArtListByUid(uid);
    }

    public Integer delArtById(Integer id, Integer uid) {
        likeRcountMapper.delArtUser(id, uid);
        return articleMapper.delArtById(id, uid);
    }

    public ArticleInfo getArtDetail(Integer id) {
        return articleMapper.getArtDetail(id);
    }

    public Integer increRCount(Integer id) {
        return articleMapper.increRCount(id);
    }

    public Integer addArt(ArticleInfo articleInfo) {
        return articleMapper.addArt(articleInfo);
    }

    public Integer updateArt(ArticleInfo articleInfo) {
        return articleMapper.updateArt(articleInfo);
    }

    public List<ArticleInfo> getArtByPage(Integer psize, Integer page) {
        return articleMapper.getArtByPage(psize, page);
    }

    public int getArtTotalCount() {
        return articleMapper.getArtTotalCount();
    }

    // 增加文章的点赞数量，并获取文章的信息
    public ArticleInfo getAddArtlikeCount(Integer aid) {
        int ret = articleMapper.addArtlikeCount(aid);
        if (ret != 1) {
            return null;
        }
        return articleMapper.getArtByaid(aid);
    }

    public int addArtLikeCount(Integer aid) {
        return articleMapper.addArtlikeCount(aid);
    }

    public int delArtLikeCount(Integer aid) {
        return articleMapper.delArtlikeCount(aid);
    }

    public int addArtTreadCount(Integer aid) {
        return articleMapper.addArtTreadCount(aid);
    }

    public int delArtTreadCount(Integer aid) {
        return articleMapper.delArtTreadCount(aid);
    }
}
